//739.每日温度
//https://leetcode.cn/problems/daily-temperatures/?envType=study-plan-v2&envId=top-100-liked
class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        int n = temperatures.size();
        if (n == 0) return {};
        if (n == 1) return { 0 };
        stack<int,vector<int>> st;
        vector<int> ret(n);
        st.push(n-1);
        for (int i = n - 2; i >= 0; --i)
        {
            while (st.size() && temperatures[i] >= temperatures[st.top()]) st.pop();
            if (st.size()) ret[i] = st.top() - i;
            st.push(i);
        }
        return ret;
    }
};